﻿@using GoodMan.Infrastructure.Entities.Entity;
@using GoodMan.Infrastructure.Entities.Contract;
@using GoodMan.Tool.Framework;
@{
    Product product = ViewBag.Product == null ? new Product() : ViewBag.Product;
    ViewBag.Title = product.ProductName;
    Layout = "~/Views/Shared/_Main.cshtml";
    Business business = ViewBag.Business == null ? new Business() : ViewBag.Business;

    string isWork = "正在营业";
    string[] startTimeArr = business.DeliveryTime.Split('|');
    string[] endTimeArr = business.DeliveryTimeEnd.Split('|');

    if (startTimeArr != null && startTimeArr.Length != 0)
    {
        for (int timeIndex = 0; timeIndex < startTimeArr.Length; timeIndex++)
        {
            if (Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + startTimeArr[timeIndex]) < DateTime.Now &&
                DateTime.Now < Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + endTimeArr[timeIndex]))
            {
                isWork = "正在营业";
            }
            else
            {
                isWork = "已打烊";
            }
        }
    }

    Policy policy = ViewBag.Ploicy == null ? new Policy() : ViewBag.Ploicy;

    ItemListBox<OrderDetail> orderDetails = ViewBag.saleRecord;
    ItemListBox<Appraise> appraiselist = ViewBag.appraiselist;

    double totalAppraise = ViewBag.totalAppraise == null ? 5.0d : ViewBag.totalAppraise;
    string Satisfaction = ViewBag.Satisfaction == null ? "100%" : ViewBag.Satisfaction;

    int IsViewAppriaseBtn = ViewBag.IsViewAppriaseBtn == null ? 0 : ViewBag.IsViewAppriaseBtn;

    int DelAuthenticate = ViewBag.DelAuthenticate == null ? 0 : ViewBag.DelAuthenticate;

    int islogin = 1;
    var loginUrl = "#";
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        islogin = 0;
        string tourl = System.Web.HttpContext.Current.Request.RawUrl;
        loginUrl = "/account/login?returnurl=" + System.Web.HttpContext.Current.Server.UrlEncode(tourl);
    }

    bool role = ViewBag.Role == null ? false : ViewBag.Role;
}


    <!--#主菜单-->
    <div class="container">
        <ul class="breadcrumb">
            <li><a href="/home/index">首页</a> <span class="divider">/</span></li>
            <li><a href="/shop/fastfood">订餐商家列表</a> <span class="divider">/</span></li>
            <li><a href="/shop/fastfoodbusiness?d=@product.BusinessId">@business.Name</a> <span class="divider">/</span></li>
            <li class="active">@product.ProductName</li>
        </ul>
        <!--//////////////////////////////////////////////////////////////////////////////////-->
        <form action="/shop/DirectPurchaseFastFood" method="post" name="buyproduct" id="buyproduct">
        <input type="hidden" name="ProductId" value="@product.Id" /> 
        <div class="row">           
            <div class="span9" style="width:96%">
                <div class="row-fluid menu-cover-box">
                    <div class="span6 covers">
                        <!--封面大小:350x240-->
                        @{
                            //月销售量
                            int sellByMonth = new OrderDetail().Count(c => c.ProductId == product.Id);

                            string imgurlproduct = "";
                            if (!string.IsNullOrEmpty(product.Images))
                            {
                                imgurlproduct = product.Images.Split(';')[0];
                            }
                            else
                            {
                                imgurlproduct = "";
                            }
                        <img class="cover" src="/content/img/hg.jpg" style="width:450px; height:300px;min-width:450px; min-height:300px;" />
                            }
                        <!--/////////////////////////////////-->
                        <div class="share">
                            <!-- JiaThis Button BEGIN -->
                            <div class="jiathis_style_32x32">
                                <a class="jiathis_button_qzone"></a><a class="jiathis_button_tsina"></a><a class="jiathis_button_tqq">
                                </a><a class="jiathis_button_renren"></a><a class="jiathis_button_kaixin001"></a>
                                <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis"
                                    target="_blank"></a><a class="jiathis_counter_style"></a>
                            </div>
                            <!-- JiaThis Button END -->
                        </div>
                    </div>
                    <div class="span6 details">
                        <div class="details">
                            
                            <h4>
                                @product.ProductName</h4>
                                <div>
                               &nbsp;
                            </div>
                            @{
                                if (policy != null && string.IsNullOrEmpty(product.Catering))
                                {
                            <div style="line-height:30px;">
                                <span class="key">销售价格：</span><span class="important text-large">&yen;@policy.Price <input type="hidden" name="Money" value="@policy.Price" /> </span></div>
                                }
                                }
                            <div style="line-height:30px;">
                                <span class="key">已销量：</span><span style=" font-weight:bold;">@sellByMonth</span>&nbsp;&nbsp;<span>单</span></div>
                                
                            <div style="line-height:30px;">
                                <span class="key">评价：</span><span><strong>4.8</strong>分&nbsp;累计评价1705</span></div>
                             <div style="line-height:30px;">
                                <span class="key">送餐时间：</span><span><b>@{

                                    if (startTimeArr != null && startTimeArr.Length != 0)
                                    {
                                        for (int i = 0; i < startTimeArr.Length; i++)
                                        {
                                      <span>@startTimeArr[i]~@endTimeArr[i]&nbsp;&nbsp;</span>
                                        }
                                    }
                                }</b></span></div>
                            <div style="line-height:30px;">
                                <span class="key">购买数量：</span><span><input type="text" id="buyNumber"  onkeyup="this.value=this.value.replace(/\D/g,'')" name="Number" maxlength="5" class="integer topic"
                                    value="1" />份</span>
                            </div>
                            <div>
                               &nbsp;
                            </div>
                             @{
                                 //没有配餐信息的时候显示
                                 if (policy != null && string.IsNullOrEmpty(product.Catering))
                                 {
                                     string disabled = "disabled=\"disabled\"";
                                     if (role)
                                     {
                                         disabled = "";
                                     }
                            <div class="">
                                @{
                                     if (islogin == 1)
                                     {
                                         if (!isWork.Equals("已打烊"))
                                         {
                                            <button  onclick="submitform()" type="button" @disabled class="btn btn-danger"><span class="icon-ok icon-white"></span>&nbsp;立即购买</button>
                                         }
                                         else
                                         { <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: #FF0000">@isWork</b></p>}
                                     }
                                     else
                                     {
                                         if (!isWork.Equals("已打烊"))
                                         {
                                            <a  onclick="@loginUrl" @disabled class="btn btn-danger"><span class="icon-ok icon-white"></span>&nbsp;立即购买</a>
                                         }
                                         else
                                         {  <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: #FF0000">@isWork</b></p>}
                                     }
                                    }
                                 
                            </div>
                                 }
                                 else
                                 {
                                 <div>
                    <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: Green">请选择配菜！</b></p>
                </div>
                                 }
                                }
                        </div>
                    </div>
                </div><br />
                <div class="clearfix" style="line-height:25px;">
                </div>
                <div class="tabbable">
                    <ul class="nav nav-tabs">
                     @{
                         //没有配餐信息的时候显示
                         if (policy != null && string.IsNullOrEmpty(product.Catering))
                         {
                        <li class="active">
                        <a href="#tab0" data-toggle="tab">套餐详情</a></li>

                         }
                         else
                         {
                          <li>
                        <a href="#tab0" data-toggle="tab">套餐详情</a></li>

                        <li class="active">
                        <a href="#tab1" data-toggle="tab">选择配菜</a></li>
                         }
                         }
                        <li><a href="#tab2" data-toggle="tab">菜品评论</a></li>
                        <li><a href="#tab3" data-toggle="tab">订购记录</a></li>
                    </ul>
                    <div class="tab-content">
                     <div class="tab-pane" id="tab0">
                     <br />
                      @Html.Raw(product.Description)
                       <br />
                                <br />
                     </div>
                        <div class="tab-pane active" id="tab1">
                            <p> 
                                @{
                                    
                                    if (!string.IsNullOrEmpty(product.Catering))
                                    {
                                        string verName = "";
                                        CateringSet catering = product.Catering.ToObject<CateringSet>();
                                        if (catering != null && catering.cateringList != null && catering.cateringList.Any())
                                        {
                                            foreach (var cItem in catering.cateringList)
                                            {
                                                if (cItem.cateringInfoList != null && cItem.cateringInfoList.Count != 0)
                                                {
                                                    verName = cItem.cateringInfoList.Count + "|" + cItem.caterCategory;                                         
                                               
                                <!--荤菜-->
                                <legend class=""><input type="hidden" name="MainFood" value="@verName" />  @cItem.caterCategory&nbsp;&nbsp;</legend>
                                                    if (cItem.cateringInfoList != null && cItem.cateringInfoList.Count != 0)
                                                    {
                                                    
                                <table class="table table-condensed table-border-none">                                    
                                
                                @{
                                                        foreach (var ciItem in cItem.cateringInfoList)
                                                        {
                                                   <tr>
                                        <td>
                                            <label>                                                
                                                @ciItem.caterName <input type="hidden" name="VerName" value="@ciItem.caterName" />
                                            </label>
                                        </td>
                                        <td>
                                            <span class="important">&yen;@ciItem.caterPrice <input type="hidden" name="VerPrice" value="@ciItem.caterPrice" /></span>
                                        </td>
                                        <td>
                                            <input type="text" name="VerNumber"  class="integer topic"  onkeyup="this.value=this.value.replace(/\D/g,'')" value="0" class="span1" onchange="setPrice(this)" /><input type="hidden" name="price" value="@ciItem.caterPrice" />
                                            份
                                        </td>
                                    </tr>
                                                        }
                                                
                                 }
                                 </table>
                                <!--#荤菜-->
                                                    }
                                                }
                                            }
                                        }

                                    }
                                  }
                               
                                <br />
                                <br />
                            </p>
                                    @{
                                        if (!string.IsNullOrEmpty(product.Catering))
                                        {
                            <!--统计-->
                            <div class="alert alert-error">
                                <div class="pull-left">
                                    <span class="important text-large">&yen;<span id="totalMoney">0.00</span><input type="hidden" id="Money" name="Money" value="" /></span>
                                    <span>&nbsp;&nbsp;每份</span> 
                                </div>
                                <div class="pull-right">
                                @{
                                            string disabled = "disabled=\"disabled\"";
                                            if (role)
                                            {
                                                disabled = "";
                                            }

                                            if (islogin == 1)
                                            {
                                                if (!isWork.Equals("已打烊"))
                                                {
                                            <button  onclick="submitformOther()" type="button" @disabled class="btn btn-danger"><span class="icon-ok icon-white"></span>&nbsp;立即购买</button>
                                                }
                                                else
                                                {  <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: #FF0000">@isWork</b></p>}
                                            }
                                            else
                                            {
                                                if (!isWork.Equals("已打烊"))
                                                {
                                            <a  href="@loginUrl"  class="btn btn-danger"><span class="icon-ok icon-white"></span>&nbsp;立即购买</a>
                                                }
                                                else
                                                {  <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: #FF0000">@isWork</b></p>}
                                            }
                                    }
                                    </div>
                                <div class="clearfix">
                                </div>
                            </div>
                            <!--#统计-->
                                        }
                                    }
                        </div>
                         <div class="tab-pane" id="tab2">
                        <p>
                            <div class="eval">
                                商品与描述相符<span class="rate">@totalAppraise</span>分&nbsp;&nbsp;@*<span class="muted">[购买商品用户登录可参与评价]</span>*@
                                @*@{
                                    if (IsViewAppriaseBtn == 1)
                                    {
                                        <a  href="javascript: doAppraise()" class="btn btn-danger" style="margin-left:50px;"><span class="icon-edit icon-white">
                                </span>&nbsp;我要评论</a>
                                    }
                                }*@
                                
                            </div>
                             <div>
                    <p style="vertical-align: middle">
                        <b style="font-size: 20px; color: Green">评价后即可获取积分购买商城积分商品！</b></p>
                </div>
                            @*@{
                                if (IsViewAppriaseBtn == 1)
                                {   
                             <div id="doAppraise" class="Hide" style="overflow:hidden;display:none">
                        <h4 class="border-bottom-gray red bg-bar">
                            &nbsp;&nbsp;我要评价</h4>
                            <div class="padding-h-10">
                               
                               <div class="row-fluid">
                               <div>评分：<span><input type="radio" value="5" checked="checked" name="appraiseGrade"/>非常满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="4"  name="appraiseGrade"/>满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="2"  name="appraiseGrade"/>一般</span>
                               &nbsp;&nbsp;<span><input type="radio" value="1"  name="appraiseGrade"/>不满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="0"  name="appraiseGrade"/>非常不满意</span> 
                               </div>
                               <br />
                               <textarea style="width:99%" name="appraiseContent" id="appraiseContent"></textarea>
                               <br />
                               <div class="text-center"><input type="button" onclick="submitAppraise()" class="btn btn-danger" value="确定"/></div>
                                </div>
                            </div>
                            </div>
                                }
                            
                        }*@
                             
                                    @{
                                        if (appraiselist != null && appraiselist.Data != null && appraiselist.Data.Any())
                                        {
                                            foreach (var Item in appraiselist.Data)
                                            {
                                                string date = Item.AppraiseDate.ToString("yyyy-MM-dd HH:mm:ss");
                                                 <div class="line-dot">
                                        </div>
                                               <div class="padding-h-10">
                                            <div class="row-fluid">
                                                <div class="span8 muted">
                                                    @Item.user.NickName &nbsp;&nbsp;&nbsp;@date &nbsp;&nbsp;&nbsp;
                                                    @{
                                                if (DelAuthenticate == 1)
                                                {
                                                            <a href="/shop/DelAppraise?id=@Item.Id&type=0&productid=@product.Id&areaCode=10" class="btn btn-danger btn-mini">删除</a>
                                                }
                                                     }
                                                </div>
                                                <div class="span4 text-right">

                                                @{
                                                for (int i = 0; i < Item.AppraiseGrade; i++)
                                                {
                                                        <img src="/content/img/star.png" />
                                                }
                                                  }
                                                     
                                                </div>
                                            </div>
                                            <small>@Item.AppraiseContent
                                            </small>
                                        </div>
                                       
                                            }
                                        }
                                    }
                                     
                                
                            <!--分页-->
                            <div class="pagination text-right" >
                                 <a href="/shop/ProductAppraises?id=@product.Id" target="_blank">更多评价>></a>
                            </div>
                            <!--#分页-->
                        </p>
                    </div>
                    <div class="tab-pane" id="tab3">
                        
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th>
                                            买家
                                        </th>
                                        <th>
                                            价格
                                        </th>
                                        <th>
                                            数量
                                        </th>
                                        <th>
                                            购买时间
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                @{
                                    if (orderDetails != null && orderDetails.Data != null && orderDetails.Data.Any())
                                    {
                                        foreach (var item in orderDetails.Data)
                                        {
                                            string orderdate = item.order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss");
                                            <tr>
                                                <td>
                                                    @item.user.NickName
                                                </td>
                                                <td>
                                                    @item.Price
                                                </td>
                                                <td>
                                                    @item.Num
                                                </td>
                                                <td>
                                                    @orderdate
                                                </td>
                                            </tr>
                                        }
                                    }
                                } 
                                </tbody>
                            </table>
                            <!--分页-->
                            <div class="pagination text-right">
                                <a href="/shop/ProductSaleRecords?id=@product.Id" target="_blank">更多记录>></a>
                            </div>
                            <!--#分页-->
                        
                    </div>
                    </div>
                </div>
                <!--//////////////////////////////////////////////////////////////////////////////////-->
            </div>
        </div>
        </form>
    </div>
    <br />
    <br />
    @section tail{
    <script type="text/javascript">
        function submitform() {
            if (parseInt($("#buyNumber").val()) == 0) {
                alert("请选择送餐份数！");
                return;
            }
            document.forms["buyproduct"].submit();
        }
        
        var totalMoney = 0.00;
        function submitformOther() {
            if (parseInt($("#buyNumber").val()) == 0) {
                alert("请选择送餐份数！");
                return;
            }
            if (parseInt(totalMoney) == 0) {
                alert("请选择配菜！");
                return;
             }

            document.forms["buyproduct"].submit();
        }
        function setPrice(e){
            //把所有的价格重新计算一遍
            totalMoney = 0.00;
            $('input[name="VerNumber"]').each(function (i) {
                var number = 0;
                if ($(this).val() == '') {
                    number = 0;
                }
                var price = parseFloat($(this).next().val());
                number = parseFloat($(this).val());
                totalMoney = parseFloat(totalMoney) + (price * number);
            });

            
            $("#totalMoney").text(returnFloat1(totalMoney));
            $("#Money").val(returnFloat1(totalMoney));
        }
        function returnFloat1(value) { //保留一位小数点
            value = Math.round(parseFloat(value) * 10) / 10;
            if (value.toString().indexOf(".") < 0)
                value = value.toString() + ".0";
            return value;
        }

        function doAppraise() {
            var obj = $("#doAppraise");
            var classstr = obj.attr("class").toString();
            if (classstr == "Hide") {
                obj.removeClass("Hide");
                obj.addClass("View");
                obj.css("display", "block");
            }
            else {
                obj.removeClass("View");
                obj.addClass("Hide");
                obj.css("display", "none");
            }
        }
        //评论
        function submitAppraise() {
            if ($("#appraiseContent").val() == '') {
                alert("请填写评论信息！");
                return;
            }
            jQuery.ajax({
                type: "Get", //用POST方式传输
                //dataType:"JSON",//数据格式:result
                url: '/shop/Appraise', //目标地址
                async: false, //作用是防止在ajax成功调用之前就调用jQuery("#Pagination").pagination,这个时候数据个数还没有初始化
                data: "pid=@product.Id&areaCode=10&appraiseGrade=" + $('input[name="appraiseGrade"]:checked').val() + "&appraiseContent=" + $("#appraiseContent").val()+"&bId=@product.BusinessId",
                cache: false,
                success: function (result) {
                    window.location.reload();
                }
            });
        }
    </script>
}